package com.example.airtest

import android.os.Bundle
import com.example.airtest.ui.state.MainActivityViewModel
import com.fandou.airobot.service.LoadAlarmsService
import com.fandou.base.ui.DataBindingConfig
import com.fandou.base.ui.activity.BaseActivity
import com.yanzhenjie.permission.AndPermission
import com.yanzhenjie.permission.runtime.Permission


class MainActivity : BaseActivity() {

    private var mMainActivityViewModel: MainActivityViewModel? = null


    override fun getDataBindingConfig(): DataBindingConfig {
        return DataBindingConfig(R.layout.activity_main, mMainActivityViewModel)
            .addBindingParam(BR.vm, mMainActivityViewModel)
    }

    override fun initViewModel() {
        mMainActivityViewModel = MainActivityViewModel()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //在程序的主入口，就重新读取加载闹钟列表
        LoadAlarmsService.launchLoadAlarmsService(this)
        requestPermission()
    }

    private fun requestPermission() {
        AndPermission.with(this)
            .runtime()
            .permission(Permission.Group.STORAGE, Permission.Group.MICROPHONE)
            .onGranted { permissions: List<String?>? ->
                // Storage permission are allowed.
            }
            .onDenied { permissions: List<String?>? ->
                showErrorToast("请先授予权限，否则语音功能将无法使用")
            }
            .start()
    }


}